#include<iostream>
#include<pthread.h>

namespace bit{
    //用Mutex类对线程原生锁进行封装，并封装它的加锁和解锁方法
    class Mutex{
    private:
        pthread_mutex_t* _mtx;
    public:
        Mutex(pthread_mutex_t* mtx):_mtx(mtx){}
        void lock(){
            pthread_mutex_lock(_mtx);
        }
        void unlock(){
            pthread_mutex_unlock(_mtx);
        }
        ~Mutex(){}
    };
    //构造时加锁，析构时解锁，一键实现自动加锁和解锁
    class LockGuard{
    private:
          Mutex _mtx;
    public:
        LockGuard(pthread_mutex_t* mtx):_mtx(mtx){
            _mtx.lock();
        }
        ~LockGuard(){
            _mtx.unlock();
        }

    };
}